<?php
$q=$_GET["q"];
$array= explode(",",$q);
$dur=$array[0];
$School_Id=$array[1];
$func=$array[2];
$hint="";
$tra=$array[3];
$Access_Type=$array[4];
$Id=$Access_Type.",".$School_Id.",School_Id";
include_once '../Login/databaseconnection.php';

if($dur!=""&&$School_Id!=""&&$tra!=""&&$func!="Select One")
{
$tra_id=mysql_query("SELECT * FROM training WHERE Training_Name='$tra'");
if($row=mysql_fetch_array($tra_id))
{
$Training_Id=$row['Training_Id'];
}
$tot_f_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Female' OR Gender='female') AND School_Id='$School_Id'");
if($tot_f_tea)
{
while($row_fe_tea=mysql_fetch_array($tot_f_tea))
{
if(empty($Female_Teachers))
{
$Female_Teachers='"'.$row_fe_tea['T_NIC_Number'].'"';
}
else
{
$Female_Teachers=$Female_Teachers.',"'.$row_fe_tea['T_NIC_Number'].'"';
}
}
}
$tot_m_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Male' OR Gender='male') AND School_Id='$School_Id'");
if($tot_m_tea)
{
while($row_ma_tea=mysql_fetch_array($tot_m_tea))
{
if(empty($Male_Teachers))
{
$Male_Teachers='"'.$row_ma_tea['T_NIC_Number'].'"';
}
else
{
$Male_Teachers=$Male_Teachers.',"'.$row_ma_tea['T_NIC_Number'].'"';
}
}
}
$get_val_male=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS males FROM training_details WHERE Duration".$func."'".$dur."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Male_Teachers)");
if($get_val_male)
{
if($row_mval=mysql_fetch_array($get_val_male))
{
$Tra_Male_Teachers=$row_mval['males'];
}
}

$get_val_female=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS females FROM training_details WHERE Duration".$func."'".$dur."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Female_Teachers)");
if($get_val_female)
{
if($row_fval=mysql_fetch_array($get_val_female))
{
$Tra_Female_Teachers=$row_fval['females'];
}
}
 if($Tra_Male_Teachers=="")
		 {
		 $Tra_Male_Teachers="0";
		 }
		 if($Tra_Female_Teachers=="")
		 {
		 $Tra_Female_Teachers="0";
		 }
$hint='<table height="105" class="imgholder1">';
$hint=$hint."<tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <th> </th>
         <td></td>
         </tr>
		 <tr>
		 <th><label>Number of male teachers:</label></th><td>";
if($Tra_Male_Teachers!="0")
{
$hint=$hint."<input type='text' name='Tra_Male_Teachers' value='$Tra_Male_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Tra_Male_Teachers' value='$Tra_Male_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>"
}
$hint=$hint."</td></tr><tr><th><label>Number of female teachers:</label></th><td>";
if($Tra_Female_Teachers!="0")
{
$hint=$hint."<input type='text' name='Tra_Female_Teachers' value='$Tra_Female_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Tra_Female_Teachers' value='$Tra_Female_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint."</td></tr></table>";
}
if($hint=="")
{
if($School_Id=="")
{
$response="<font color='red'>*Please select a school!</font>";
}
$response=$response.'<table height="105" class="imgholder1">';
$response=$response."<tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <th> </th>
         <td></td>
         </tr>
		 <tr>
		 <th><label>Number of male teachers:</label></th><td><input type='text' name='Tra_Male_Teachers' readonly='readonly' onmouseover='clearpopbox()'/></td></tr><tr><th><label>Number of female teachers:</label></th><td><input type='text' name='Tra_Female_Teachers' readonly='readonly' onmouseover='clearpopbox()'/></td></tr></table>";
}
else
{
$response=$hint;
}
echo $response;
?>